function [s_out,g] = equal_snr_precode(s_in,h,noise,power,nr,nt)


v=noise*diag(diag(ones(nr)));
Rnn=v*v';
[V,gamma]=eig(h'*inv(Rnn)*h,'nobalance');
B=rank(h);


p0=nt*power;

Inr=diag(diag(ones(B)));

lambda=p0 / trace(inv(gamma));
phi_f=sqrt(lambda) * inv(sqrt(gamma));
phi_g=sqrt(lambda) * inv( (sqrt(gamma)*inv(lambda*1)) );

g=V'*h'*inv(Rnn)*phi_g;
f=phi_f*V;
g=phi_g*V'*h'*inv(Rnn);
f=V*phi_f;
s_out=f*s_in;

